import http from '../utils/request';
import { baseURL } from '../utils/base_url'
import { getStorage } from '../utils/common'


// 响应接口
interface GetTlUserAuthRes {
	code : number;
	data : {
		authStatus : number;
		bankCardBindStatus : number;
		bindStatus : number;
		signStatus : number;
	};
	msg : string;
}
// 响应接口
interface GetApiMerCashCardListRes {
	code : number;
	data : {
		bankName : string;
		bankcardNum : string;
		id : string;
	}[];
	msg : string;
}

interface GetMerCashCardDetailRes {
	code : number;
	data : {
		bankName : string;
		bankcardNum : string;
		id : string;
		phone : string;

	};
	msg : string;
}

interface DefaultRes {
	code : number;
	data : string;
	msg : string;
}

// 响应接口
export interface GetXxPayInfoRes {
	code : number;
	data : Record<string, any>;
	msg : string;
}


// 获取通联绑定手机号验证码
export function getTlSmsCodeForBind() : Promise<DefaultRes> {
	return http('/api/auth/allinPay/getTlSmsCodeForBind') as any
}

/** 
 * 商户--获取认证信息
 * @returns
 */
interface GetAuthCompanyInfoRes {
	code : number;
	data : {
		accountStatus : number;
		accountType : string;
		authStatus : number;
		bankBranchName : string;
		bankCardBindStatus : number;
		bankDeposit : string;
		bankNo : string;
		bankReservedMobile : string;
		bindStatus : number;
		businessLicensePic : string;
		createTime : Record<string, unknown>;
		enterpriseType : string;
		facePicUploadStatus : number;
		id : string;
		legalCheckStatus : number;
		legalIdCardFacePic : string;
		legalIdCardNationalEmblemPic : string;
		legalIdNum : string;
		legalMobile : string;
		legalName : string;
		licenseCheckStatus : number;
		licensePicUploadStatus : number;
		merAuthName : string;
		merId : string;
		nationalEmblemPicUploadStatus : number;
		registerNum : string;
		signStatus : number;
		tlId : string;
		unionBank : string;
		updateTime : Record<string, unknown>;
		legalSignStatus: number
	};
	msg : string;
}
export function getTlUserAuth() : Promise<GetAuthCompanyInfoRes> {
	return http('/api/auth/mer/auth/getAuthCompanyInfo') as any
}

// 获取通联签约链接
export function getSignUrl(prams : { loginType : number, accountType: string }) : Promise<DefaultRes> {
	return http('/api/auth/allinPay/getSignUrl', prams) as any
}

// 获取通联签约链接
export function tlDelete(params : { id : string }) : Promise<DefaultRes> {
	return http('/api/auth/mer/card/delete', params, 'DELETE') as any
}


// 通联相关 获取商户提现信息列表
export function getApiMerCashCardList() : Promise<GetApiMerCashCardListRes> {
	return http('/api/auth/mer/card/getApiMerCashCardList') as any
}
// 通联相关 获取商户提现账户详情
export function getMerCashCardDetail(params : { id : string }) : Promise<GetMerCashCardDetailRes> {
	return http('/api/auth/mer/card/getMerCashCardDetail', params) as any
}




// 通联相关 绑定银行卡

interface AddUserCardParams {
  accountType?: string;
  bankBranchName?: string;
  bankDeposit?: string;
  bankcardNum?: string;
  phone?: string;
  unionBank?: string;
}

export function addMerCashCard(params : AddUserCardParams) : Promise<GetMerCashCardDetailRes> {
	return http('/api/auth/mer/card/addMerCashCard', params, 'POST') as any
}


// 手机号绑定
export function createUserAndBindPhone(params : {
	"mobile" : string,
	"smsCode" : string
}) : Promise<DefaultRes> {
	return http('/api/auth/allinPay/createUserAndBindPhone', params, 'POST') as any
}

// 通联支付---创建订单回调
export function payNotify() : Promise<DefaultRes> {
	return http('/api/unAuth/allinPayCallBack/payNotify', {}, 'POST') as any
}
// 通联支付--退款回调
export function refundNotify() : Promise<DefaultRes> {
	return http('/api/unAuth/allinPayCallBack/refundNotify', {}, 'POST') as any
}
// 通联支付---签约回调
export function signNotify() : Promise<DefaultRes> {
	return http('/api/unAuth/allinPayCallBack/signNotify', {}, 'POST') as any
}
// 通联支付---提现回调
export function withdrawNotify() : Promise<DefaultRes> {
	return http('/api/unAuth/allinPayCallBack/withdrawNotify', {}, 'POST') as any
}
// 获取小象支付信息
export function getXxPayInfo(params : { orderId : string | number }) : Promise<GetXxPayInfoRes> {
	return http('/api/auth/station/getXxPayInfo', params) as any
}

/** 
 * 商户--认证企业
 * @param {object} params req
 * @param {string} params.accountType 账户类别  mer_account_type 字典
 * @param {string} params.bankBranchName 开户支行名称
 * @param {string} params.bankDeposit 开户行
 * @param {string} params.bankNo 银行卡号
 * @param {string} params.bankReservedMobile 银行预留手机号
 * @param {string} params.enterpriseType 企业性质. enterprise_type 字典
 * @param {string} params.legalIdNum 法人身份证号
 * @param {string} params.legalMobile 法人 手机号
 * @param {string} params.legalName 法人姓名
 * @param {string} params.merAuthName 企业名称
 * @param {string} params.registerNum 注册号
 * @param {string} params.smsCode 短信验证码
 * @param {string} params.unionBank 支付行号，12位数字
 * @returns
 */

// 参数接口
interface AuthCompanyInfoParams {
	accountType ?: string;
	bankBranchName ?: string;
	bankDeposit ?: string;
	bankNo ?: string;
	bankReservedMobile ?: string;
	enterpriseType ?: string;
	legalIdNum ?: string;
	legalMobile ?: string;
	legalName ?: string;
	merAuthName ?: string;
	registerNum ?: string;
	smsCode ?: string;
	unionBank ?: string;
}

export function authCompanyInfo(params : AuthCompanyInfoParams) : Promise<DefaultRes> {
	return http('/api/auth/mer/auth/authCompanyInfo', params, 'POST') as any
}


/** 
 * 商户--获取银行信息
 * @param {string} keywords 关键字
  * @returns
 */


interface GetAuthBankListRes {
	code : number;
	data : Record<string, unknown>[];
	msg : string;
}

export function getAuthBankList(params : { keywords : string }) : Promise<GetAuthBankListRes> {
	return http('/api/auth/mer/auth/getAuthBankList', params, 'GET') as any
}


/** 
 * 商户--获取认证信息
 * @returns
 */

interface GetAuthCompanyInfoRes {
	code : number;
	data : {
		accountStatus : number;
		accountType : string;
		authStatus : number;
		bankBranchName : string;
		bankCardBindStatus : number;
		bankDeposit : string;
		bankNo : string;
		bankReservedMobile : string;
		bindStatus : number;
		businessLicensePic : string;
		createTime : Record<string, unknown>;
		enterpriseType : string;
		facePicUploadStatus : number;
		id : string;
		legalCheckStatus : number;
		legalIdCardFacePic : string;
		legalIdCardNationalEmblemPic : string;
		legalIdNum : string;
		legalMobile : string;
		legalName : string;
		licenseCheckStatus : number;
		licensePicUploadStatus : number;
		merAuthName : string;
		merId : string;
		nationalEmblemPicUploadStatus : number;
		registerNum : string;
		signStatus : number;
		tlId : string;
		unionBank : string;
		updateTime : Record<string, unknown>;
	};
	msg : string;
}


export function getAuthCompanyInfo() : Promise<GetAuthCompanyInfoRes> {
	return http('/api/auth/mer/auth/getAuthCompanyInfo') as any
}



export function saveMerAuthImages(params : {
	"businessLicensePic" : string,
	"legalIdCardFacePic" : string,
	"legalIdCardNationalEmblemPic" : string
}) : Promise<GetAuthCompanyInfoRes> {
	return http('/api/auth/mer/auth/saveMerAuthImages', params, 'POST') as any
}